﻿using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using ESRI.ArcGIS.Client.FeatureService;

namespace ESRI.ArcGIS.Client.Async
{
    public static partial class ArcGISDynamicMapServiceLayerExtensions
    {
        /// <summary>
        /// Gets all details for sub-layers or tables.
        /// </summary>
        /// <param name="layer"></param>
        /// <returns></returns>
        public static Task<IDictionary<int, FeatureLayerInfo>> GetAllDetailsTaskAsync(this ArcGISDynamicMapServiceLayer layer)
        {
            if (layer == null) throw new ArgumentNullException("layer");
            return TaskServices.HandleActionWithCallbackArgument<IDictionary<int, FeatureLayerInfo>>(layer.GetAllDetails);
        }

        /// <summary>
        /// Gets the sub-layer or table details (for a specific ID) of an ArcGISDynamicMapServiceLayer.
        /// </summary>
        /// <param name="layer"></param>
        /// <param name="id">The sub-layer or table id.</param>
        /// <returns></returns>
        public static Task<FeatureLayerInfo> GetDetailsTaskAsync(this ArcGISDynamicMapServiceLayer layer, int id)
        {
            if (layer == null) throw new ArgumentNullException("layer");
            return TaskServices.HandleActionWithCallbackArgument<int, FeatureLayerInfo>(layer.GetDetails, id);
        }
    }
}